package com.mrliu.undertow.service.impl;


import com.mrliu.undertow.mapper.UserGrowthValueInfoMapper;
import com.mrliu.undertow.mapper.UserInfoMapper;
import com.mrliu.undertow.pojo.UserGrowthValueInfo;
import com.mrliu.undertow.pojo.UserInfo;
import com.mrliu.undertow.service.UserInfoService;
import com.mrliu.undertow.util.IdWorker;
import com.mrliu.undertow.util.Mod;

import cn.hutool.core.date.DateUtil;

import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;


/**
 * @author Administrator
 */
@Service
public class UserInfoServiceImpl implements UserInfoService {

    @Resource
    private UserInfoMapper userInfoMapper;
    
    
    @Resource
    UserGrowthValueInfoMapper userGrowthValueInfoMapper;
    
    @Resource
    IdWorker   idWorker;


    @Override
    public List<UserInfo> selectList() {
        return userInfoMapper.selectList();
    }
    
    @Override
    public List<UserGrowthValueInfo> selectGrowList() {
       
        return  userGrowthValueInfoMapper.selectAll();
    }

    /* (non-Javadoc)
     * @see com.mrliu.undertow.service.UserInfoService#addData()
     */
    @Override
    public String addData() {
        addRoeData();
        return "Success";
    }

    /**
     * 方法描述：
     */
    @Async  
    private void addRoeData() {
        
        List<Mod> map = getMap();
        List<Long> ids = getIds();
       // Date date = new Date("2018-01-01 00:00:00");
        Date date = DateUtil.parseDate("2018-01-01 00:00:00").toJdkDate();
        
        for(int i=0;i<1;i++) {
       // for(int i=0;i<1000000;i++) {
            List<UserGrowthValueInfo> list = getList(ids,date,map);
            userGrowthValueInfoMapper.insertList(list);
        }
        
    }

    /**
     * 方法描述：
     * @return
     */
    private List<Mod> getMap() {
       List<Mod> results = new ArrayList<Mod>();
       
       results.add(new Mod("被关注",40,"CCW001"));
       results.add(new Mod("被关注",40,"CCH001"));
       results.add(new Mod("被关注",40,"CCT001"));
       
       results.add(new Mod("被点赞",1,"CCW001"));
       results.add(new Mod("被点赞",1,"CCH001"));
       results.add(new Mod("被点赞",1,"CCT001"));
       
       
       results.add(new Mod("关注他人",5,"CCW001"));
       results.add(new Mod("关注他人",5,"CCH001"));
       results.add(new Mod("关注他人",5,"CCT001"));
       
        return results;
    }

    /**
     * 方法描述：
     * @return
     */
    private List<Long> getIds() {
        List<Long> ids = new ArrayList<Long>();
        
        for(int i=0;i<1;i++) {
            ids.add(idWorker.nextId());
        }
        return ids;
    }

    /**
     * 方法描述：
     * @param ids 
     * @param date 
     * @param map 
     * @return
     */
    private List<UserGrowthValueInfo> getList(List<Long> ids, Date date, List<Mod> map) {
        List<UserGrowthValueInfo> list =new ArrayList<UserGrowthValueInfo>();
        Random random = new Random();
       for(int i=0;i<1;i++) {
           date = DateUtil.offsetSecond(date, 10);
           int n = random.nextInt(ids.size());
           int n2 = random.nextInt(map.size());
           UserGrowthValueInfo info = new UserGrowthValueInfo();
           info.setId(idWorker.nextId());
           info.setBeanId(ids.get(n)+"");
           info.setOemId("CC01");
           info.setOperateType(1);
           info.setCreateTime(date.toLocaleString());
           Mod mod  = map.get(n2);
           info.setBrandId(mod.getBranchId());
           info.setRemark(mod.getRemark());
           info.setPointValue(mod.getPoint());
           info.setPortCode("auto");
           System.out.println(info);
           list.add(info);
       }
        return list;
    }
    
}